<?php
ImportClass('json');

$id				= gpc_getIntPost("id",$id);
$oldUrl 		= gpc_getStringPost("oldUrl");
$name       	= gpc_getStringPost("Name");
$urlstring		= gpc_getStringPost("URL",$name);
$title			= gpc_getStringPost("Title",$name);
$parentId       = gpc_getIntPost("ParentId");
$TopBottomOrder	= gpc_getIntPost("TopBottomOrder",-1);
$order 			= gpc_getIntPost("Order",-1);
$Status 		= gpc_getIntPost("Status");
$sologan 		= gpc_getStringPost("Sologan");
$description 	= gpc_getStringPost("Description");
$Intro			= gpc_getStringPost("Intro");
$IntroTour  	= gpc_getStringPost("IntroTour");
$IntroHotel  	= gpc_getStringPost("IntroHotel");
$Tag 			= gpc_getStringPost("Tag");

//where
$TitleWhere 	= gpc_getStringPost("TitleWhere");
$Where      	= gpc_getStringPost("Where");
$ReadMoreWhere	= gpc_getStringPost("ReadMoreWhere");
$arrcode        = array("title"=>$TitleWhere,"msg"=>$Where,"readmore"=>$ReadMoreWhere);
$Where          = FJSON::encode($arrcode);

//when
$TitleWhen   	= gpc_getStringPost("TitleWhen");
$When      	    = gpc_getStringPost("When");
$ReadMoreWhen	= gpc_getStringPost("ReadMoreWhen");
$arrcode        = array("title"=>$TitleWhen,"msg"=>$When,"readmore"=>$ReadMoreWhen);
$When           = FJSON::encode($arrcode);

//highlights
$Highlights	    = gpc_getStringPost("Highlights");
$ReadMoreHighlights	= gpc_getStringPost("ReadMoreHighlights");
$arrcode        = array("msg"=>$Highlights,"readmore"=>$ReadMoreHighlights);
$Highlights     = FJSON::encode($arrcode);

//Quick Facts
$QuickFacts	    = gpc_getStringPost("QuickFacts");
$ReadMoreQuickFacts	= gpc_getStringPost("ReadMoreQuickFacts");
$arrcode        = array("msg"=>$QuickFacts,"readmore"=>$ReadMoreQuickFacts);
$QuickFacts     = FJSON::encode($arrcode);

//Practical tips
$TitlePracticalTips   	= gpc_getStringPost("TitlePracticalTips");
$PracticalTips  = gpc_getStringPost("PracticalTips");
$ReadMorePracticalTips	= gpc_getStringPost("ReadMorePracticalTips");
$arrcode        = array("title"=>$TitlePracticalTips,"msg"=>$PracticalTips,"readmore"=>$ReadMorePracticalTips);
$PracticalTips  = FJSON::encode($arrcode);

//Visa
$TitleVisa   	= gpc_getStringPost("TitleVisa");
$Visa           = gpc_getStringPost("Visa");
$ReadMoreVisa 	= gpc_getStringPost("ReadMoreVisa");
$arrcode        = array("title"=>$TitleVisa,"msg"=>$Visa,"readmore"=>$ReadMoreVisa);
$Visa           = FJSON::encode($arrcode);

//Travel tips
$TitleTravelTips= gpc_getStringPost("TitleTravelTips");
$TravelTips     = gpc_getStringPost("TravelTips");
$ReadMoreTravelTips 	= gpc_getStringPost("ReadMoreTravelTips");
$arrcode        = array("title"=>$TitleTravelTips,"msg"=>$TravelTips,"readmore"=>$ReadMoreTravelTips);
$TravelTips     = FJSON::encode($arrcode);

//FAQs
$TitleFAQs      = gpc_getStringPost("TitleFAQs");
$FAQs           = gpc_getStringPost("FAQs");
$ReadMoreFAQs	= gpc_getStringPost("ReadMoreFAQs");
$arrcode        = array("title"=>$TitleFAQs,"msg"=>$FAQs,"readmore"=>$ReadMoreFAQs);
$FAQs           = FJSON::encode($arrcode);


$metatitle 		= gpc_getStringPost("MetaTitle",$name);
$metakeywords 	= gpc_getStringPost("MetaKeywords");
$metadescription= gpc_getStringPost("MetaDescription",strip_tags($description));

$ImgIntro 		= gpc_getStringPost('ImgIntro');
$ImgBanner 		= gpc_getStringPost('ImgBanner');
//------==============-------------------
$urlstring      = Trim_Url($urlstring);

if(empty($name))
{
	error_transfer("Name is empty. please enter name!");
}

$description = replace_pathlocal($description);
$Intro		 = replace_pathlocal($Intro);
$IntroTour   = replace_pathlocal($IntroTour);
$Where		 = replace_pathlocal($Where);
$When		 = replace_pathlocal($When);
$Highlights	 = replace_pathlocal($Highlights);
$metadescription=strip_tags($metadescription);


CheckUrlString($urlstring,"tbllocation",$parentId);

$order=GetOrderForInsert($TopBottomOrder,$order,$parentId,"tbllocation");

if($act=="insert")
{
    $postdate   = date("Y-m-d");
    $poster     = getUserNamePost();

	$sql_insert = "INSERT INTO tbllocation
				(iParentId,cUrlString , cName, cDescription,cIntro,
                cWhere,cWhen,cHighlights,cQuickFacts,cPracticalTips,
                cVisa,cTravelTips,cFAQs,cIntroTour,cIntroHotel,
				cMetaTitle, cMetaDescription, cMetaKeywords ,cImage, cBanner,
				iStatus,iOrder,dPostDate,dPoster,cLanguage)
			VALUE
				('$parentId','$urlstring','$name','$description','$Intro',                
                '$Where','$When','$Highlights','$QuickFacts','$PracticalTips',
                '$Visa','$TravelTips','$FAQs','$IntroTour','$IntroHotel',
				'$metatitle','$metadescription','$metakeywords','$ImgIntro','$ImgBanner',
				'$Status','$order','$postdate','$poster','$language')";

	$dbsql->query($sql_insert);

    Insert_Tracking("Add Location : $name ");
    page_transfer("Add Location [ $name ] Success !","id=$parentId");
}
elseif($id>0)
{
    $sql_update="update tbllocation set ";
    $sql_update.="iParentId     = '".$parentId."', ";
    $sql_update.="cUrlString    = '".$urlstring."', ";
    $sql_update.="cName         = '".$name."', ";
    $sql_update.="cDescription  = '".$description."', ";
    $sql_update.="cIntro        = '".$Intro."', ";
    $sql_update.="cWhere        = '".$Where."', ";
    $sql_update.="cWhen         = '".$When."', ";
    $sql_update.="cHighlights   = '".$Highlights."', ";
    $sql_update.="cQuickFacts   = '".$QuickFacts."', ";
    $sql_update.="cPracticalTips= '".$PracticalTips."', ";
    
    $sql_update.="cVisa         = '".$Visa."', ";
    $sql_update.="cTravelTips   = '".$TravelTips."', ";
    $sql_update.="cFAQs         = '".$FAQs."', ";
    $sql_update.="cIntroTour    = '".$IntroTour."', ";
    $sql_update.="cIntroHotel   = '".$IntroHotel."', ";
    
    $sql_update.="cMetaTitle    = '".$metatitle."', ";
    $sql_update.="cMetaDescription= '".$metadescription."', ";
    $sql_update.="cMetaKeywords = '".$metakeywords."', ";
    $sql_update.="cImage        = '".$ImgIntro."', ";
    $sql_update.="cBanner       = '".$ImgBanner."', ";
    if($order>0)
    {
        $sql_update.="iOrder        = '".$order."', ";
    }
    $sql_update.="iStatus       = '".$Status."' ";
    $sql_update.="where iId=".$id;
    $dbsql->query($sql_update);

    Insert_Tracking( " Edit Location : $name ");
    page_transfer("Update Location [ $name ] Success",getUrlBack());
}
exit();
?>